package com.mhc.haval.manager.impl;

import com.mhc.haval.dal.mapper.ext.StaffExtMapper;
import com.mhc.haval.dal.model.FuncDO;
import com.mhc.haval.dal.model.RoleDO;
import com.mhc.haval.dal.model.StaffDO;
import com.mhc.haval.dal.query.StaffQuery;
import com.mhc.haval.manager.StaffManager;
import com.subaru.common.query.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * Manager for Staff.
 */

@Service
public class StaffManagerImpl implements StaffManager{

    
    @Autowired
    protected StaffExtMapper staffExtMapper;
    /**
     * query count by query condition.
     */
    @Override
    public int countByQuery(StaffQuery query){
        return staffExtMapper.countByQuery(query);
    }

    /**
     * delete by query condition.
     */
    @Override
    public int deleteByQuery(StaffQuery query){
        return staffExtMapper.deleteByQuery(query);
    }

    /**
     * delete by primary key.
     */
    @Override
    public int deleteByPrimaryKey(StaffDO record){
        return staffExtMapper.deleteByPrimaryKey(record);
    }

    /**
     * insert selective.
     */
    @Override
    public long insertSelective(StaffDO record){
        return staffExtMapper.insertSelective(record);
    }

    /**
     * select by query condition.
     */
    @Override
    public List<StaffDO> selectByQuery(StaffQuery query){
        return staffExtMapper.selectByQuery(query);
    }

    /**
     * select by query condition with page.
    */
    @Override
    public PageResult<StaffDO> selectByQueryWithPage(StaffQuery query) {
        PageResult<StaffDO> result = new PageResult<StaffDO>();
        result.setPageSize(query.getPageSize());
        result.setPageNo(query.getPageNo());
        result.setTotalCount(this.countByQuery(query));
        result.setResult(this.selectByQuery(query));
        return result;
    }

    /**
     * select by primary key.
     */
    @Override
    public StaffDO selectByPrimaryKey(Long id){
        return staffExtMapper.selectByPrimaryKey(id);
    }

    /**
     * select by staff phone.
     */
    @Override
    public StaffDO selectByStaffPhone(String staffPhone) {
        return staffExtMapper.selectByStaffPhone(staffPhone);
    }

    /**
     * update by query condition selective.
     */
    @Override
    public int updateByQuerySelective( StaffDO record,  StaffQuery query){
        return staffExtMapper.updateByQuerySelective(record,  query);
    }

    /**
     * update by query condition.
     */
    @Override
    public int updateByQuery( StaffDO record,  StaffQuery query){

        return staffExtMapper.updateByQuery(record, query);
    }

    /**
     * update by primary key selective.
     */
    @Override
    public int updateByPrimaryKeySelective(StaffDO record){
        return staffExtMapper.updateByPrimaryKeySelective(record);
    }

    /**
     * 获取用户拥有的角色
     */
    @Override
    public List<RoleDO> selectRoleListByStaffPhone(String staffPhone) {
        return staffExtMapper.selectRoleListByStaffPhone(staffPhone);
    }

    /**
     * 获取用户拥有的功能
     */
    @Override
    public List<FuncDO> selectFuncListByStaffPhone(String staffPhone) {
        return staffExtMapper.selectFuncListByStaffPhone(staffPhone);
    }

    /**
     * 根据角色id获取对应的员工列表
     * @param queryMap
     * @return
     */
    @Override
    public List<StaffDO> selectStaffListByRoleCode(Map queryMap) {
        return staffExtMapper.selectStaffListByRoleCode(queryMap);
    }
}